<!-- INCLUDE ../include/title.html -->

<body>

<div class="ch-container">
    <div class="row">

        <div id="content" >




    <div class="box col-md-12">

            <div class="box-content">
                <span id="errormessage">
                </span>
                <form role="form" id="form" method="post"  name="modifyclass" action="index.php?do=Record/record_add">
                    <input type="hidden" name="action" value="modify"/>
                    <input type="hidden" name="TaskID" value="{TaskID}"/>
                    <input type="hidden" id="defaultChannelID" value="{defChannelID}"/>

                    <input type="hidden" name="ClassID" value="{ClassID}"/>
                    <div class="form-group">
                        <label for="ChannelID">频道名</label>                      
                            <select class="form-control" id="ChannelID" name = "ChannelID">
                                {ChannelID}
                            </select>
                    </div>


                    <div class="form-group">
                        <label for="TaskName">任务名称</label>
                        <input type="text" value="{TaskName}" readonly name="TaskName" id="TaskName" class="form-control">
                    </div>

                    <div class="form-group">
                        <label for="FileName">文件名</label>
                        <input type="text" value="{FileName}" placeholder="请输入文件名"  name="FileName" id="FileName" class="form-control">
                    </div>



                    <div class="form-group">
                        <label for="StreamID">流信息</label>                      
                            <select class="form-control" name = "StreamID">
                                {StreamID}
                            </select>
                    </div>

                    <div class="form-group">
                        <label for="BeginTime">开始时间</label> 
                            <input type="text" value="{BeginTime}"  name="BeginTime" placeholder="请输入开始时间，格式：yyyy-mm-dd HH:MM:SS" id="BeginTime" class="form-control">                   
                    </div>

                    <div class="form-group">
                        <label for="EndTime">结束时间</label> 
                            <input type="text" value="{EndTime}" name="EndTime" placeholder="请输入结束时间，格式：yyyy-mm-dd HH:MM:SS" id="EndTime" class="form-control">                   
                    </div>

                   

                     <div class="form-group">
                        <label for="FilePath">文件路径</label>                      
                            <input type="text" value="{FilePath}" readonly name="FilePath"  id="FilePath" class="form-control">  
                    </div>

                    <div class="form-group cleanfloat">
                        <button class="btn btn-default" onclick="submits()" type="button">提交</button>
                    </div>
                </form>
            </div>
    <!--/span-->

</div>


</div><!--/.fluid-container-->


<!-- INCLUDE ../include/bottom.html -->



<script>
    var channel_json = {channel_json};


    function geterrormsg (content) {
        // body...
        var errormsg='<div class="alert alert-danger "><button data-dismiss="alert" class="close" type="button">×</button><span >'+content+'</span></div>';
            $("#errormessage").html(errormsg);
    }

    function submits(){
        check();
    }

    function check(){
        var BeginTime = $("#BeginTime").val();
        var EndTime = $("#EndTime").val();
        var ChannelID = $("#ChannelID").val();
        $.get("./index.php?do=index/Ajax&action=CheckRecordTime&ChannelID="+ChannelID+"&BeginTime="+BeginTime+'&EndTime='+EndTime,function(data){
            data = eval("("+data+")");
            var msg = '';
            switch (parseInt(data['error'])){
                case 1 :
                    geterrormsg('开始时间或者结束时间格式错误！');
                    $(".alerterrormsg").show();
                    return false;
                    break;
                case 2 :
                    geterrormsg( '开始时间或者结束时间不能小于当前时间！');
                    $(".alerterrormsg").show();
                    return false;
                    break;
                case 3 :
                    geterrormsg( '开始时间不能小于结束时间！');
                    $(".alerterrormsg").show();
                    return false;
                    break;
                case 4 :
                    if (window.confirm("录制任务时间有重复，请确认继续？")){
                        $("#form").submit();
                    }else{
                        return false;
                    }
                    break;
                case 5 :
                    $("#form").submit();
                    break;

            }
        })



    }

    function loadDefaultChannel(){
        var ChannelID = $("#defaultChannelID").val();
        var ChannelName = '';
        if (ChannelID.length>0) {
            for (var i = 0; i < channel_json.length; i++) {
                if (ChannelID == channel_json[i].ChannelID){
                    ChannelName = channel_json[i].ChannelName;
                    break;
                }
            }
            $("#ChannelID").val(ChannelID);
             UpdateChannel(ChannelID,ChannelName);
        }

    }


    $("#ChannelID").change(function(){
         UpdateChannel($(this).val(),$(this).find("option:selected").text());
    })


    function UpdateChannel(val,text){
        //var text = $(this).find("option:selected").text();
        //var val = $(this).val();
        var time1 = new Date().Format("yyyyMMddhhmmss");
        if (!parseInt(val)==0) {
            $("#TaskName").val(text+"_"+time1);
            $("#FileName").val(text+"_"+time1+".rmvb");
            for (var i = 0; i < channel_json.length; i++) {
                if (val == channel_json[i].ChannelID){
                    $("#FilePath").val(channel_json[i].RecordFilePath);
                    break;
                }
            };
        }else{
            $("#TaskName").val('');
            $("#FileName").val('');
            $("#FilePath").val('');
        }
    }

    

    loadDefaultChannel();
</script>


</body>